package com.zry.yard.config

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.os.Environment
import com.baidu.mapapi.CoordType
import com.baidu.mapapi.SDKInitializer
import com.zry.yard.retrofit.persistentcookiejar.ClearableCookieJar
import com.zry.yard.retrofit.persistentcookiejar.PersistentCookieJar
import com.zry.yard.retrofit.persistentcookiejar.cache.SetCookieCache
import com.zry.yard.retrofit.persistentcookiejar.persistence.SharedPrefsCookiePersistor


import java.util.concurrent.ExecutorService
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit


class MyApplication : Application() {
    /**
     * 线程池
     */
    val cachedThreadPool: ExecutorService = ThreadPoolExecutor(8, 8, 0L,
            TimeUnit.MILLISECONDS, LinkedBlockingQueue(100000),
            ThreadPoolExecutor.CallerRunsPolicy())

    /**
     * 图片保存路径
     */
    val photoSavePath = Environment.getExternalStorageDirectory().absolutePath + "/jianguan/image/"

    /**
     * 视频保存路径
     */
    val videoSavePath = Environment.getExternalStorageDirectory().absolutePath + "/jianguan/video/"

    /**
     * 音频文件保存路径
     */
    val audioSavePath = Environment.getExternalStorageDirectory().absolutePath + "/jianguan/audio/"

    /**
     * 文件保存路径
     */
    val apkSavePath = Environment.getExternalStorageDirectory().absolutePath + "/jianguan/"

    /**
     * 配置缓存
     */
    lateinit var cookieJar: ClearableCookieJar


    companion object {
        @SuppressLint("StaticFieldLeak")
        var instance: MyApplication? = null

        fun instance() = instance!!


        @SuppressLint("StaticFieldLeak")
        private var mContext: Context? = null

        fun mContext() = mContext!!
    }


    override fun onCreate() {
        super.onCreate()

        instance = this

        mContext = applicationContext

        cookieJar = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(instance))

        SDKInitializer.initialize(this)
        SDKInitializer.setCoordType(CoordType.BD09LL)

    }


}
